package com.cq.hd.rabbit.consumer;

import com.alibaba.fastjson.JSON;
import com.cq.hd.common.constant.RabbitMqConstant;
import com.cq.hd.common.entity.mq.ActiveBrowseMsg;
import com.cq.hd.product.api.TbActiveBrowseApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Slf4j
@RabbitListener(queues = RabbitMqConstant.ACTIVE_BROWSE_QUEUE)
public class ActiveBrowseMsgConsumer {

    @Autowired
    private TbActiveBrowseApi activeBrowseApi;

    @RabbitHandler
    public void receiveMsg(Map map) {
        log.info("activeBrowseMsg消息：{}", map.toString());
//        String messageId = (String) map.get("messageId");
        String messageData = (String) map.get("messageData");
        ActiveBrowseMsg activeBrowseMsg = JSON.parseObject(messageData, ActiveBrowseMsg.class);

        try {
            activeBrowseApi.consumerActiveBrowseMsg(activeBrowseMsg);
        } catch (Exception e) {
            log.error("消费activeBrowseMsg消息失败，activeBrowseMsg：{}", messageData, e);
        }
    }

}
